//
//  Protocol.swift
//  CosClub
//
//  Created by iOS on 2020/4/2.
//  Copyright © 2020 ios. All rights reserved.
//

import Foundation
import UIKit

//MARK: ViewModel协议
public protocol ViewModelType {
    associatedtype Input
    associatedtype Output
    
    var input: Input! {get}
    var output: Output! {get}
}

//MARK: cellId 协议
public protocol CellProtocol {
    static var identifier: String {get}
}

extension CellProtocol where Self : UIView{
    public static var identifier: String {
        return NSStringFromClass(self.classForCoder()) + "identifier"
    }
}
extension UITableViewCell: CellProtocol {}
extension UICollectionReusableView: CellProtocol {}



/// cell被选择
public protocol CellCanChooseProtocol {
    var defalutBorderColor: UIColor {get}
    var selectedBorderColor: UIColor {get}
    func selectedStatus(_ isSelected: Bool)
}

extension UICollectionViewCell: CellCanChooseProtocol {

    public var defalutBorderColor: UIColor {
        UIColor.app.c1
    }
    
    public var selectedBorderColor: UIColor {
        UIColor.app.z33
    }
    
    
    public func selectedStatus(_ isSelected: Bool) {
        if isSelected {
            self.layer.borderColor = self.defalutBorderColor.cgColor
        }else {
            self.layer.borderColor = self.selectedBorderColor.cgColor
        }
    }
}


//MARK: - 圆角协议
public protocol AbleMask {
    func addMask(_ backgroundColor: UIColor, corners:UIRectCorner, cornerRadius:CGFloat)
    func addRoundMask(_ backgroundColor: UIColor)
}

extension AbleMask where Self : UIView {
    
    public func addRoundMask(_ backgroundColor: UIColor = UIColor.app.white) {
        addMask(backgroundColor, cornerRadius: self.bounds.size.height/2)
    }
    
    public func addMask(_ backgroundColor: UIColor = UIColor.app.white, corners:UIRectCorner = .allCorners, cornerRadius:CGFloat = 0) {
        
        let path = UIBezierPath(rect: self.bounds)
        let path2 = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: cornerRadius, height: cornerRadius))
        path.append(path2)
        path.usesEvenOddFillRule = true
        
        let shapeLayer = CAShapeLayer()
        shapeLayer.path = path.cgPath
        shapeLayer.fillRule = .evenOdd
        shapeLayer.fillColor = backgroundColor.cgColor
        
        //添加图层蒙板
        self.layer.addSublayer(shapeLayer)
    }
}

extension UIView: AbleMask {}
